package com.ciwong.listenspeak.wxapi;

import com.ciwong.mobilepay.weixin.WxPayHelper;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler
{
    private WxPayHelper mPayHelper;

    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        try {
            mPayHelper = mPayHelper.getInstance();
            if(null!=getIntent()||null!=mPayHelper){
                mPayHelper.getIWXAPI().handleIntent(getIntent(), this);
            }
        }catch (Exception e){
            e.getStackTrace();
        }
    }

    @Override
    protected void onNewIntent(Intent intent)
    {
        super.onNewIntent(intent);
        setIntent(intent);
        mPayHelper.getIWXAPI().handleIntent(intent, this);
    }

    @Override
    public void onReq(BaseReq req)
    {
        mPayHelper.dealWithWeixinOnResp(req);
    }

    @Override
    public void onResp(BaseResp resp)
    {
        mPayHelper.dealWithWeixinOnResp(resp);
        finish();
    }
}